﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


using Umbraco.Courier.Core;
using Umbraco.Courier.Core.ProviderModel;
using Umbraco.Courier.Core.Diagnostics.Logging;

namespace DeleteUnpublishedDocuments
{
public class UnPublishDocument : ItemEventProvider
{
    public override string Alias
    {
        get{ return "DeleteDocument"; }
    }

    public override void Execute(ItemIdentifier itemId, SerializableDictionary<string, string> Parameters)
    {
        Guid g;
        //if the itemId is a valid Guid we will fetch a umbraco document from it
        if (Guid.TryParse(itemId.Id, out g))
        {
            try
            {
                //get the native umbraco document object
                umbraco.cms.businesslogic.web.Document d = new umbraco.cms.businesslogic.web.Document(g);
                        
                //call the native umbraco document api .delete();
                if (d != null)
                    d.delete();
                    
            }
            catch (Exception ex)
            {
                //logging of errors
                RevisionLog.Instance.AddItemEntry(itemId, this.GetType(), "DeleteDocument", ex.ToString(), LogItemEntryType.Error);
            }
        }
    }
}
    
}